﻿Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary

'Imports System.Net.Mime.MediaTypeNames.Image
'Imports System.Media
'Imports System.Net.Mime.MediaTypeNames

Public Class Gestion

    Public Sub New()

    End Sub

    ' ================================== Cargar es una función o un subprograma

    Public Sub CrearDirectorio()

        If Not Directory.Exists(My.Application.Info.DirectoryPath & "\Datos\") Then
            Directory.CreateDirectory(My.Application.Info.DirectoryPath & "\Datos\")
        End If

    End Sub

    Public Function CargarClientes() As Dictionary(Of String, Cliente)

        Dim diccionario As New Dictionary(Of String, Cliente)

        Try
            Dim fichero As New FileStream("Datos\Clientes.txt", FileMode.Open)
            Dim binary As New BinaryFormatter()
            diccionario = CType(binary.Deserialize(fichero), Dictionary(Of String, Cliente))
            fichero.Close()
        Catch ex As Exception

        End Try

        Return diccionario

    End Function

    Public Function CargarPedidos() As Dictionary(Of String, Pedido)

        Dim diccionario As New Dictionary(Of String, Pedido)

        Try
            Dim fichero As New FileStream("Datos\Pedidos.txt", FileMode.Open)
            Dim binary As New BinaryFormatter()
            diccionario = CType(binary.Deserialize(fichero), Dictionary(Of String, Pedido))
            fichero.Close()
        Catch ex As Exception

        End Try

        Return diccionario

    End Function

    Public Function CargarMesas() As Dictionary(Of String, Mesa)

        Dim diccionario As New Dictionary(Of String, Mesa)

        Try
            Dim fichero As New FileStream("Datos\Mesas.txt", FileMode.Open)
            Dim binary As New BinaryFormatter()
            diccionario = CType(binary.Deserialize(fichero), Dictionary(Of String, Mesa))
            fichero.Close()
        Catch ex As Exception

        End Try

        Return diccionario

    End Function

    Public Function CargarProductos() As Dictionary(Of String, Producto)

        Dim diccionario As New Dictionary(Of String, Producto)

        Try
            Dim fichero As New FileStream("Datos\Productos.txt", FileMode.Open)
            Dim binary As New BinaryFormatter()
            diccionario = CType(binary.Deserialize(fichero), Dictionary(Of String, Producto))
            fichero.Close()
        Catch ex As Exception

        End Try

        Return diccionario

    End Function

    Public Function CargarOfertas() As Dictionary(Of String, Oferta)

        Dim diccionario As New Dictionary(Of String, Oferta)

        Try
            Dim fichero As New FileStream("Datos\Ofertas.txt", FileMode.Open)
            Dim binary As New BinaryFormatter()
            diccionario = CType(binary.Deserialize(fichero), Dictionary(Of String, Oferta))
            fichero.Close()
        Catch ex As Exception

        End Try

        Return diccionario

    End Function

    Public Sub GrabarClientes(ByVal diccionario As Dictionary(Of String, Cliente))

        Try
            Dim fichero As New FileStream(My.Application.Info.DirectoryPath & "\Datos\Clientes.txt", FileMode.Create)
            Dim binary As New BinaryFormatter()
            binary.Serialize(fichero, diccionario)
            fichero.Close()
        Catch ex As Exception

        End Try

    End Sub

    Public Sub GrabarPedidos(ByVal diccionario As Dictionary(Of String, Pedido))

        Try
            Dim fichero As New FileStream(My.Application.Info.DirectoryPath & "\Datos\Pedidos.txt", FileMode.Create)
            Dim binary As New BinaryFormatter()
            binary.Serialize(fichero, diccionario)
            fichero.Close()
        Catch ex As Exception

        End Try

    End Sub

    Public Sub GrabarMesas(ByVal diccionario As Dictionary(Of String, Mesa))

        Try
            Dim fichero As New FileStream(My.Application.Info.DirectoryPath & "\Datos\Mesas.txt", FileMode.Create)
            Dim binary As New BinaryFormatter()
            binary.Serialize(fichero, diccionario)
            fichero.Close()
        Catch ex As Exception

        End Try
    End Sub

    Public Sub GrabarProductos(ByVal diccionario As Dictionary(Of String, Producto))

        Try
            Dim fichero As New FileStream(My.Application.Info.DirectoryPath & "\Datos\Productos.txt", FileMode.Create)
            Dim binary As New BinaryFormatter()
            binary.Serialize(fichero, diccionario)
            fichero.Close()
        Catch ex As Exception

        End Try
    End Sub

    Public Sub GrabarOfertas(ByVal diccionario As Dictionary(Of String, Oferta))

        Try
            Dim fichero As New FileStream(My.Application.Info.DirectoryPath & "\Datos\Ofertas.txt", FileMode.Create)
            Dim binary As New BinaryFormatter()
            binary.Serialize(fichero, diccionario)
            fichero.Close()
        Catch ex As Exception

        End Try
    End Sub


    'Public Function CargarClientes() As Dictionary(Of String, Cliente)

    '    Dim cont As Integer = 0
    '    If Not File.Exists(My.Application.Info.DirectoryPath & "\Datos\" & nombre & ".txt") Then File.Create(My.Application.Info.DirectoryPath & "\Datos\" & nombre & ".txt")
    '    Dim ficR As StreamReader

    '    ficR = New StreamReader(My.Application.Info.DirectoryPath & "\Datos\" & nombre & ".txt")
    '    Dim datos() As String
    '    Dim diccionarioCliente As New Dictionary(Of String, Cliente)
    '    Dim linea As String
    '    Do Until ficR.EndOfStream
    '        linea = ficR.ReadLine()
    '        datos = linea.Split("*")
    '        Dim cliente As New Cliente(datos(0), datos(1), datos(2), datos(3), datos(4))
    '        diccionarioCliente.Add(cliente.Nombre, cliente)


    '    Loop





    '    Return diccionarioCliente

    'End Function

    'Public Function CargarPedidos(ByVal nombre As String) As Dictionary(Of String, Pedido)

    '    Dim cont As Integer = 0
    '    If Not File.Exists(My.Application.Info.DirectoryPath & "\Datos\" & nombre & ".txt") Then File.Create(My.Application.Info.DirectoryPath & "\Datos\" & nombre & ".txt")
    '    Dim ficR As StreamReader

    '    ficR = New StreamReader(My.Application.Info.DirectoryPath & "\Datos\" & nombre & ".txt")
    '    Dim datos() As String
    '    Dim diccionarioPedido As New Dictionary(Of String, Pedido)
    '    Dim linea As String
    '    Do Until ficR.EndOfStream
    '        linea = ficR.ReadLine()
    '        datos = linea.Split("*")
    '        '        Dim pedido As New Pedido(datos(0), datos(1), datos(2), datos(3), datos(4))
    '        '       diccionarioPedido.Add(Cliente.Nombre, pedido)


    '    Loop


    'End Function


End Class
